import axios, { AxiosRequestConfig } from 'axios'
const request = axios.create({
  baseURL: 'http://www.pankshare.com'
})

// 请求拦截器
request.interceptors.request.use(function (config) {
  // 同意设置请求配置
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// 相应拦截器
request.interceptors.response.use(function (response) {
  // 统一设置接口响应异常
  return response
}, function (error) {
  // Any status codes that falls outside the range of 2xx cause this function to trigger
  // Do something with response error
  return Promise.reject(error)
})

export default <T = any> (config: AxiosRequestConfig) => {
  return request(config).then(res => {
    return res.data as T
  })
}
